package com.elite.groovy.callback
import groovy.json.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import com.elite.groovy.util.EliteBean;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.dataservice.Result;
import groovy.swing.impl.DefaultAction;
import java.util.Map;
import java.util.Date;
import java.util.HashMap;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;

import com.elite.groovy.util.Util;
import cn.com.kh.HttpClientProxy;

public class selMessage implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(selMessage.class);
	public String doCallBack(EliteBean eliteBean,HttpServletRequest request,HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");
		log.debug("start selMessage-----------------");
		log.debug("request--:" + request);
		
		def o_offerno="";
		def o_quoteno="";
		def o_type="";
		
		o_offerno= request.getParameter("offerno");
		o_quoteno= request.getParameter("quoteno");
		o_type= request.getParameter("type");
		
		log.debug("o_offerno:" + o_offerno);
		log.debug("o_quoteno:" + o_quoteno);
        log.debug("o_type:" + o_type);
		
		def querySql1 = "select webserviceurl from sysc_interface where webtype='D23-1'";
		def queryList1=eliteBean.chaxun_sql(querySql1, "dataSource");
		def queryMap1=queryList1[0];
		def httpURL=queryMap1.get("webserviceurl");
				
	     def sendBody="<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"REQUEST\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>D23</REQUEST_TYPE></HEAD><BODY><OFFER_NO>"+o_offerno+"</OFFER_NO><QUOTE_NO>"+o_quoteno+"</QUOTE_NO><TYPE>"+o_type+"</TYPE></BODY></PACKET>";

						
        try {
			log.debug("系统转发调用发送URL:" + httpURL + " 发送报文:" + sendBody);

			String coreResult = HttpClientProxy.sendPost(httpURL, sendBody, "",8888);
			
			def contentone=coreResult.replaceAll("&", "");
			def contenttwo=contentone.replaceAll("lt;", "<");
			def contentthree=contenttwo.replaceAll("gt;", ">");
			def contentfour=contentthree.replaceAll("quot;", "\"");
			
			log.debug("调用返回替换字符处理结果:" + contentfour);

			return contentfour;
			
		} catch (Exception e) {
			log.debug("调用异常:" + e.getMessage());
		}						
		
			
    }
}